<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            list-style-type: none;
        }
        ul {
            display: flex;
            justify-content: center;
            border: 1px solid black;
            margin: 20 auto;
        }
        li {
            height: 100px;
            width: 100px;
            margin: 10px;
            background-color: rgb(126, 21, 239);
        }
    </style>
</head>
<body>
    <ul>
        <li style="opacity: 1;"></li>
        <li style="opacity: 1;"></li>
        <li style="opacity: 1;"></li>
    </ul>
    <script>
        const ul = document.querySelector("ul")

        ul.addEventListener("mouseover", (e) => {
            if (e.target.nodeName == "LI") {
                move(e.target, 0.2)
            }
        })
        ul.addEventListener("mouseout", (e) => {
            if (e.target.nodeName == "LI") {
                move(e.target, 1)
            }
        })

        let time;
        function move(a, b) {           //a:目标；b:透明度
            clearInterval(a.time);
            
            let end = b * 100
            let speed = 2
            
            a.time = setInterval(() => {
                let start = a.style.opacity * 100
                if (start > end) {
                    if (start > end) {
                        start -= speed;
                        a.style.opacity = start / 100
                    } else {
                        clearInterval(a.time);
                        a.style.opacity = b
                    }
                }
                if (start < end) {
                    if (start < end) {
                        start += speed;
                        a.style.opacity = start / 100
                    } else {
                        clearInterval(a.time);
                        a.style.opacity = b
                    }
                }
            }, 50)
        }
        

    </script>
</body>
</html>